package com.liuscraft.tradingplatform.properties;


import com.liuscraft.tradingplatform.interceptors.DefaultLuckVerifyInterceptor;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

/**
 * @author LiusCraft
 * @date 2023/3/5 21:01
 */
/*@Component
@ConfigurationProperties(
        prefix = "luck-permission",
        ignoreUnknownFields = true
)*/
@ConfigurationProperties(
        prefix = "luck-permission"
)
@Getter
@Setter
public class LuckProperties {
    private static LuckProperties luckProperties;

    public static LuckProperties getLuckProperties() {
        if (luckProperties == null) luckProperties = new LuckProperties();
        return luckProperties;
    }

    public LuckProperties() {
        luckProperties = this;
    }
    @Deprecated
    // 超级管理员角色名称（弃用了）
    private String superAdminName = "SuperAdmin";

    // 要被扫描的controller包
    private String[] packages = {};
    // 校验拦截器指定，请指定自己的实现
    private Class[] verifyInterceptors = {DefaultLuckVerifyInterceptor.class};
    // 是否每次启动都检查并刷新权限信息
    private Boolean refreshPermission = true;
    // 当发现权限表中的权限在项目中被删除，权限表的权限是否直接删除（不需询问）
    private Boolean deleteNotFoundPermission = false;
    // 表的相关配置
    private final Table table = new Table();
    @Data
    public static class Table {
        // 权限表的名称
        private String permissionName = "luck_permission";
        // 角色表的名称
        private String roleName = "luck_role";
        // 角色与权限关联表的名称
        private String rolePermissionName = "luck_role_permission";
    }

    public void setPackages(String[] packages) {
        this.packages = packages;
        if (packages == null || packages.length==0) throw new RuntimeException("请指定controller包路径");
    }
}
